<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <%@ include file="/pages/common/header.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("#search-button").click(function () {
                location.href = 'ManagerUserServlet?action=pageBlur&username=' + $("#search-input").val();
                return false;
            });
        });
    </script>
</head>
<body>
<div class="info">
    <span class="displayedUsername">${sessionScope.user.username}</span>
    <a href="UserServlet?action=logout" class="exit">退出登录</a>
</div>
<h1>用户管理</h1>
<table id="content" style="width: 600px; margin-top: 40px">
    <tr id="search-box">
        <td colspan="3"><input type="text" name="search" placeholder="输入用户名（支持模糊搜索）" id="search-input"
                               style="width: 200px;" value="${requestScope.username}">
            <input type="button" value="搜索" name="search" id="search-button" style="margin-left: 10px"></td>
        <td></td>
        <td><input type="button" value="新建" name="create" id="create-button" onclick="location.href='ManagerUserServlet?action=addRedirect&pt=${page.pt}'"></td>
    </tr>
    <tr>
        <th>编号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>类型</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${page.pes}" var="user">
        <tr>
            <td class="id">${user.id}</td>
            <td class="username">${user.username}</td>
            <td class="password">${user.password}</td>
            <td class="type">
                <c:choose>
                    <c:when test="${user.type == 1}">
                        管理员
                    </c:when>
                    <c:otherwise>
                        普通用户
                    </c:otherwise>
                </c:choose>
            </td>
            <td class="action">
                <button class="edit" onclick="location.href='ManagerUserServlet?action=queryById&id=${user.id}&pn=${page.pn}'">编辑</button>
                <button class="delete">删除</button>
            </td>
        </tr>
    </c:forEach>
</table>
<%@ include file="/pages/common/page_nav.jsp" %>
</body>
</html>